#import "dfhgwhruebvhrheyprofessionalincidentally.h"
#import "dfhgwhruebvhrheygarbageequator.h"
#import "dfhgwhruebvhrheydiscardreveal.h"
#import "dfhgwhruebvhrheypeapasture.h"
@implementation dfhgwhruebvhrheypeapasture  {
	UIButton *confirmBtn;
	void(^_callback)(int type);
	dfhgwhruebvhrheydiscardreveal *repaymentView;
	dfhgwhruebvhrheydiscardreveal *principalView;
	dfhgwhruebvhrheydiscardreveal *interestView;
	dfhgwhruebvhrheydiscardreveal *overdueFeesView;
	dfhgwhruebvhrheydiscardreveal *repaidAmountView;
	dfhgwhruebvhrheydiscardreveal *couponView;
}
- (instancetype)initWithFrame:(CGRect)frame {
	if(self = [super initWithFrame:frame]) {
		[self setUI];
	}
	return self;
}
- (void)setUI {
	self.layer.cornerRadius = 20;
	self.layer.masksToBounds = YES;
	self.backgroundColor = [UIColor whiteColor];
	repaymentView = [[dfhgwhruebvhrheydiscardreveal alloc] init];
	repaymentView.backgroundColor = primary_color.dhgfywegwygeydwlearneddesignate;
	[repaymentView setTextColor:[UIColor whiteColor]];
	[repaymentView updateTitle:@"Total Repayment" andValue:@"PHP 0" isHiddenLine:NO];
	[self addSubview:repaymentView];
	principalView = [[dfhgwhruebvhrheydiscardreveal alloc] init];
	[principalView updateTitle:@"Principal" andValue:@"PHP 0" isHiddenLine:NO];
	[self addSubview:principalView];
	interestView = [[dfhgwhruebvhrheydiscardreveal alloc] init];
	[interestView updateTitle:@"Interest" andValue:@"PHP 0" isHiddenLine:NO];
	[self addSubview:interestView];
	overdueFeesView = [[dfhgwhruebvhrheydiscardreveal alloc] init];
	[overdueFeesView updateTitle:@"Overdue Fees" andValue:@"PHP 0" isHiddenLine:NO];
	[self addSubview:overdueFeesView];
	repaidAmountView = [[dfhgwhruebvhrheydiscardreveal alloc] init];
	[repaidAmountView updateTitle:@"Repaid Amount" andValue:@"PHP 0" isHiddenLine:NO];
	[self addSubview:repaidAmountView];
	couponView = [[dfhgwhruebvhrheydiscardreveal alloc] init];
	[couponView updateTitle:@"Coupon" andValue:@"PHP 0" isHiddenLine:NO];
	[self addSubview:couponView];
	UITapGestureRecognizer *couponViewTap = [[UITapGestureRecognizer alloc] init];
	[couponViewTap addTarget:self action:@selector(couponTapAction)];
	[couponView addGestureRecognizer:couponViewTap];
	confirmBtn = [UIButton buttonWithType:UIButtonTypeCustom];
	confirmBtn.titleLabel.font = [UIFont semiBold:15];
	confirmBtn.layer.cornerRadius = 10;
	confirmBtn.backgroundColor = primary_color.dhgfywegwygeydwlearneddesignate;
	[confirmBtn setTitle:@"Full Payment" forState:UIControlStateNormal];
	[confirmBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
	[confirmBtn addTarget:self action:@selector(confirmBtnAction) forControlEvents:UIControlEventTouchUpInside];
	[self addSubview:confirmBtn];
}
- (void)couponTapAction {
	if(_callback){
		_callback(1);
	}
}
- (void)confirmBtnAction {
	if(_callback){
		_callback(2);
	}
}
- (void)bindData:(dfhgwhruebvhrheygarbageequator *)data andCallBack:(void(^)(int type))callback {
	_callback = callback;
	NSString *principalString = [NSString stringWithFormat:@"%@",data.money].dhgfywegwygeydwlocalitylearned;
	[principalView updateTitle:@"Principal" andValue:[NSString stringWithFormat:@"PHP %@",principalString] isHiddenLine:NO];
	NSString *interestString = [NSString stringWithFormat:@"%d",data.all_interest].dhgfywegwygeydwlocalitylearned;
	[interestView updateTitle:@"Interest" andValue:[NSString stringWithFormat:@"PHP %@",interestString] isHiddenLine:NO];
	if(data.overtime_price == 0) {
		overdueFeesView.hidden = YES;
		[overdueFeesView mas_updateConstraints:^(MASConstraintMaker *make) {
			make.height.mas_equalTo(0);
		}];
	}else {
		NSString *overtime_priceString = [NSString stringWithFormat:@"%d",data.overtime_price].dhgfywegwygeydwlocalitylearned;
		[overdueFeesView updateTitle:@"Overdue Fees" andValue:[NSString stringWithFormat:@"PHP %@",overtime_priceString] isHiddenLine:NO];
	}
	if([data.repaid_amount intValue] == 0) {
		repaidAmountView.hidden = YES;
		[repaidAmountView mas_updateConstraints:^(MASConstraintMaker *make) {
			make.height.mas_equalTo(0);
		}];
	}else {
		NSString *repaidString = [NSString stringWithFormat:@"%@",data.repaid_amount].dhgfywegwygeydwlocalitylearned;
		[repaidAmountView updateTitle:@"Repaid Amount" andValue:[NSString stringWithFormat:@"PHP %@",repaidString] isHiddenLine:NO];
	}
	if (self.existCouopon) {
		int counponMoney = self.coupon.selected ? self.coupon.arch_money : 0;
		[couponView updateTitle:@"Coupon" andValue:[NSString stringWithFormat:@"-PHP %d", counponMoney] isHiddenLine:YES];
	}else {
		couponView.hidden = YES;
		[couponView mas_updateConstraints:^(MASConstraintMaker *make) {
			make.height.mas_equalTo(0);
		}];
	}
	int amount = data.final_amount - (self.coupon.selected ? self.coupon.arch_money : 0);
	NSString *amountString = [NSString stringWithFormat:@"%d",amount].dhgfywegwygeydwlocalitylearned;
	[repaymentView updateTitle:@"Total Repayment" andValue:[NSString stringWithFormat:@"PHP %@",amountString] isHiddenLine:NO];
}
- (void)layoutSubviews {
	[super layoutSubviews];
	[repaymentView mas_makeConstraints:^(MASConstraintMaker *make) {
		make.left.top.right.equalTo(self);
		make.height.mas_equalTo(50);
	}];
	[principalView mas_makeConstraints:^(MASConstraintMaker *make) {
		make.top.equalTo(repaymentView.mas_bottom);
		make.left.centerX.equalTo(repaymentView);
		make.height.mas_equalTo(50);
	}];
	[interestView mas_makeConstraints:^(MASConstraintMaker *make) {
		make.top.equalTo(principalView.mas_bottom);
		make.left.centerX.equalTo(principalView);
		make.height.mas_equalTo(50);
	}];
	[overdueFeesView mas_makeConstraints:^(MASConstraintMaker *make) {
		make.top.equalTo(interestView.mas_bottom);
		make.left.centerX.equalTo(interestView);
		make.height.mas_equalTo(50).priorityHigh();
	}];
	[repaidAmountView mas_makeConstraints:^(MASConstraintMaker *make) {
		make.top.equalTo(overdueFeesView.mas_bottom);
		make.left.centerX.equalTo(overdueFeesView);
		make.height.mas_equalTo(50).priorityHigh();
	}];
	[couponView mas_makeConstraints:^(MASConstraintMaker *make) {
		make.top.equalTo(repaidAmountView.mas_bottom);
		make.left.centerX.equalTo(repaidAmountView);
		make.height.mas_equalTo(50).priorityHigh();
	}];
	[confirmBtn mas_makeConstraints:^(MASConstraintMaker *make) {
		make.top.equalTo(couponView.mas_bottom).offset(10);
		make.size.mas_equalTo(CGSizeMake(130, 45));
		make.centerX.equalTo(self);
		make.bottom.equalTo(self).offset(-20);
	}];
}
@end
